package com.base.myproject.client.ui;




import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.ui.HTML;
/**
 * 
 * @author Administrator
 *2010-7-11
 * javazgw@gmail.com
 * @Deprecated  2010-07-11
 * 
 */
@Deprecated 
public class BaseRatifyDialog extends Dialog implements RequestCallback{
	 String busicode,bcode,vprepare = null;
	 String busistatus,maintablename,icode = null;
	 SelectionListener<ButtonEvent> listener;
	HTML html = new HTML();
	public BaseRatifyDialog(String busicode,String vprepare, String bcode)
	{
		this.busicode = busicode;
		this.bcode = bcode;
		this.vprepare = vprepare;
		init();
	}
	public void init()
	{
		initListener();
		this.setLayout(new RowLayout(Orientation.VERTICAL));
	
		//panel.add(grid, new RowData(.2, 1));  
		try {
			sendServlet("PRERITIFY", "gwtbase/BaseServlet", "Action=prerityfy&busicode="+getBusicode()+"&bcode="+getBcode());
			
		} catch (RequestException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ContentPanel toppanel = new ContentPanel();
		toppanel.setHeaderVisible(false);
		toppanel.setScrollMode(Scroll.AUTOY);
		toppanel.add(html);
		
		ContentPanel centerpanel = new ContentPanel();
		centerpanel.setHeaderVisible(false);
		centerpanel.add(new HTML("在此处加入提示内容！"));
		
		ContentPanel footerpanel = new ContentPanel();
		footerpanel.setHeaderVisible(false);
		Button ratify = new Button("审批通过");//或者提交审批，后面补上如果是第一次的话，那么就是提交审批，下面按钮不要出现
		ratify.setId("ratify_ratify");
		Button ratifyno = new Button("审批不通过");
		ratifyno.setId("ratify_ratifyno");
		Button ratifydetail= new Button("查看单据明细");
		ratifydetail.setId("ratify_ratifydetail");
		footerpanel.setLayout(new TableLayout(3));
		footerpanel.add(ratify );
		footerpanel.add(ratifyno);
		footerpanel.add(ratifydetail);
		footerpanel.setWidth("100%");
		ratify.addSelectionListener(listener);
		ratifyno.addSelectionListener(listener);
		ratifydetail.addSelectionListener(listener);
//		
//		footerpanel.setLayout(new FlowLayout());
//		footerpanel.add(ratify);
//		footerpanel.add(ratifyno);
//		footerpanel.add(ratifydetail);
//		footerpanel.setWidth("100%");
		this.add(toppanel,new RowData(1, 0.3));
		this.add(centerpanel,new RowData(1, 0.6));
		this.add(footerpanel,new RowData(1, 0.1));
		setBodyBorder(false);  
	
	    setButtons(Dialog.OK);  
	    setIconStyle("icon-app-side");  
	    setHeading("审批对话框");  
	    setWidth(600);  
	    setHeight(400);  
	    setHideOnButtonClick(true);  
	}

	public boolean sendServlet(String servletflag,String url,String form) throws RequestException
	{
		
		RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,URL.encode(url));  
		builder.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");  
// form = "Action=aaa&age=13";  
		//builder.setRequestData(form);
		builder.sendRequest(form,this);  
		return true;
	}
	
	/**
	 * @return the icode
	 */
	public String getIcode() {
		return icode;
	}
	/**
	 * @param icode the icode to set
	 */
	public void setIcode(String icode) {
		this.icode = icode;
	}
	public String getBusistatus() {
		return busistatus;
	}
	public void setBusistatus(String busistatus) {
		this.busistatus = busistatus;
	}
	public String getMaintablename() {
		return maintablename;
	}
	public void setMaintablename(String maintablename) {
		this.maintablename = maintablename;
	}
	public String getBusicode() {
		return busicode;
	}
	public void setBusicode(String busicode) {
		this.busicode = busicode;
	}
	public String getBcode() {
		return bcode;
	}
	public void setBcode(String bcode) {
		this.bcode = bcode;
	}
	
	void initListener()
	{
		 listener =new  SelectionListener<ButtonEvent>()
		{

			
			 
			@Override
			public void componentSelected(ButtonEvent ce) {
				System.out.println(""+ce.getButton().getId());
				if (ce.getButton().getId().equals("ratify_ratify")) {
					try {
						sendServlet("ratify", "gwtbase/BaseServlet",
								"Action=Ratify&busicode=" + getBusicode()
										+ "&bcode=" + getBcode()
										+ "&busistatus=" + getBusistatus()
										+ "&maintablename="
										+ getMaintablename()+"&icode="+getIcode()+"&vprepare="+vprepare);
					} catch (RequestException e) {

						e.printStackTrace();
					}
				} else if (ce.getButton().getId().equals("ratify_ratifyno")) {

				} else if (ce.getButton().getId().equals("ratify_ratifydetail")) {

				}

				
			}  
		
		};
	}
	@Override
	public void onError(Request request, Throwable exception) {
		// TODO Auto-generated method stub
		
		MessageBox.alert("错误", "读取审批链的时候出现了错误！", null);
	}
	@Override
	public void onResponseReceived(Request request, Response response) {
		// TODO Auto-generated method stub
		System.out.println(response.getText());
	//	html.setHTML("<table style='width:100%'><tr><td>1001<img src=\"/images/base/arrow.gif\" /><table><tr><td><img src=\"/images/base/man1.gif\" /></td><td>1002</td></tr></table><img src=\"/images/base/arrow.gif\" /><table><tr><td><img src=\"/images/base/man1.gif\" /></td><td>1004</td></tr></table></td></tr><table>");
	//	html.setHTML("<table style='width:100%'>1001<img src=\"/images/base/arrow.gif\" /><img src=\"/images/base/man1.gif\" />1002<img src=\"/images/base/arrow.gif\" /><img src=\"/images/base/man1.gif\" />1004</td></tr><table>");
		html.setHTML(response.getText());
		
		html.setWidth("100%");
	}
	
}
